import React, { Component } from "react";
import PropTypes from "prop-types"

export default class Parent extends Component {
  render() {
    return (
      <>
        <h2>Parent</h2>
        <A name="wukong" age="20"/>
      </>
    );
  }
}

class A extends Component {
  render() {
    const { name, age, sex } = this.props;
    return (
      <>
        <h3>A Child</h3>
        <div>{name}</div>
        <div>{age}</div>
        <div>{sex}</div>
      </>
    );
  }
}

// 在类的外部对于类型进行限制
A.propTypes = {
  name:PropTypes.string.isRequired,
  age:PropTypes.number,
  sex:PropTypes.string
}

// 在类的外部进行默认值
A.defaultProps = {
  sex:"female"
}


